<?php

/**
 * Goods_cart_model short summary.
 *
 * Goods_cart_model description.
 *
 * @version 1.0
 * @author GALAXY
 */
class Goods_cart_model extends CI_Model
{
    public $goods_cart_id;
    public $goods_id;
    public $count;
    public $color_id;
    public $size_id;
    public $customer_id;
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    public function get_goods_cart_count($customer_id)
    {
        $sql="select count(*) as cart_count from goods_cart where customer_id=".$customer_id;
        return $this->db->query($sql)->row();
    }
    public function get_cart_by_id($cart_id)
    {
        $sql="select * from goods_cart where goods_cart_id=".$cart_id;
        return $this->db->query($sql)->row();
    }
    public function add_cart($goodscart_model)
    {
        return $this->db->insert('goods_cart',$goodscart_model);
    }

    public function get_goods_carts($customer_id)
    {
        $sql="SELECT goods_cart.*,color.title,size.title as sizetitle,goods.title as goodstitle,goods.shop_price,goods.thumbnail_img FROM goods_cart LEFT JOIN color on color.color_id=goods_cart.color_id LEFT JOIN size on size.size_id=goods_cart.size_id LEFT JOIN goods on goods.goods_id=goods_cart.goods_id where goods_cart.customer_id=$customer_id";
        return $this->db->query($sql)->result();
    }

    public function del_cart($cart_id)
    {
        return $this->db->delete('goods_cart',array('goods_cart_id'=>$cart_id));
    }

    public function update_cart_count($cartid,$new_val)
    {
        $sql="update goods_cart set count=$new_val where goods_cart_id=$cartid";
        return $this->db->query($sql);
    }
}